<div class="modal fade" id="cancel" tabindex="-1" role="dialog" >
    <div class="modal-dialog" role="document">
        <form class="form-ajax" action="?md=shop&cl=shop&at=cancelExpressOrder"
              method="post" autocomplete="off">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="exampleModalLabel">取消指派</h4>
                </div>
                <div class="modal-body">
                    <input type="hidden" id="cancel_id" name="cancel_id"/>
                    <input type="hidden" id="ridersTel" name="ridersTel"/>
                    <div>
                        请确认是否要取消指派，取消指派后，此订单会退回到“未指派订单“区块
                    </div>

                    <br/>
                    <div class="form-group">
                        <label>选择取消原因:</label>
                        <select name="cancel" class="form-control select" id="cancelSelect">
                            <option value="">请选择...</option>
                            <?php
							if (!empty($cancel_code)){
								foreach($cancel_code as $v){
									echo '<option value="'.$v['cancel_code'].'">'.$v['cancel_name'].'</option>';
								}
							}
							?>
                        </select>
                    </div>

                    <div class="form-group" id="cancelInfo" style="display: none">
                        <label>请填写取消原因:</label>
                        <input type="text" class="form-control" name="cancelInfo" value="">
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                    <button type="button" id="sub" class="btn btn-primary">提交</button>
                </div>
            </div>
        </form>
    </div>
</div>
<script>
    function cancel(id,ridersTel){
        $("#cancel_id").val(id);
        $("#ridersTel").val(ridersTel);
    }

    $("#sub").click(function () {
        var cancelSelect = $("#cancelSelect").val();
        if(cancelSelect == ''){
            $(this).attr('type','button');
            alert("请选择取消原因");
            return;
        }else{
            if(cancelSelect == 10000){
                var inp = $("#cancelInfo").find('input').val();
                if(inp == ''){
                    $(this).attr('type','button');
                    alert("请填写取消原因");
                }else{
                    $(this).attr('type','submit')
                }
            }else{
                $(this).attr('type','submit')
            }
        }
    });

    $("#cancelSelect").change(function () {
        var code = $("#cancelSelect").val();
        if(code == 10000) {
            $("#cancelInfo").show();
        }else{
            $("#cancelInfo").hide();
        }
    })

</script>